
***************************************************************************************************************
********** THIS .DO FILE PERFORMS A BOOTSTRAP EXERCISE TO MAKE INFERENCE ABOUT SUBSAMPLE DIFFERENCES **********
***************************************************************************************************************
version 16.1
clear*


**********************************************************
** DEFINE PROGRAM THAT CALCULATES SUBSAMPLE DIFFERENCES **
**********************************************************
program subsample_test, rclass

syntax varlist (min=2 max=2)

token `varlist'
local outcome `1'
local subsample `2'

qui rdrobust `outcome' margin_mayor_left if `subsample'==0,  vce(cluster mun_code) all

tempname non_subs subs
scalar `non_subs'=e(tau_bc)

qui rdrobust `outcome' margin_mayor_left if `subsample'==1,  vce(cluster mun_code) all
scalar `subs'=e(tau_bc)

return scalar subsample_difference= `subs' - `non_subs'

end


******************
** OPEN DATASET **
******************

use "${root}/data/processed/final_sample.dta", clear


keep if baseline_sample == 1
*keep only relevant variables, to reduce computation time
keep res_social_exp_avg_share res_social_exp_avg_pc oil_sample mun_code margin_mayor_left year lame_duck tiebout_median_sample tiebout_75th_sample coal_dist_median_sample coal_dist_75th_sample


*********************************************************************
** BOOTSTRAP S.E.s FOR DIFFERENTIAL EFFECTS ON THE SOC. EXP. SHARE **
**********************************************************************

duplicates report

xtset,clear

subsample_test res_social_exp_avg_share oil_sample
bootstrap oil_difference=r(subsample_difference), nodots cluster(mun_code) seed(123456) reps(500): subsample_test res_social_exp_avg_share oil_sample

local oil_share_b  : di %9.2f e(b)[1,1]
local oil_share_se : di %9.2f e(se)[1,1]

xtset,clear

subsample_test res_social_exp_avg_share lame_duck
bootstrap lame_duck_difference=r(subsample_difference), nodots cluster(mun_code) seed(123456) reps(500): subsample_test res_social_exp_avg_share lame_duck

local lameduck_share_b :  di %9.2f e(b)[1,1]
local lameduck_share_se : di %9.2f e(se)[1,1]

xtset,clear

subsample_test res_social_exp_avg_share tiebout_median_sample
bootstrap tiebout_median_difference=r(subsample_difference), nodots cluster(mun_code) seed(123456) reps(500): subsample_test res_social_exp_avg_share tiebout_median_sample

local tmed_share_b  : di %9.2f e(b)[1,1]
local tmed_share_se : di %9.2f e(se)[1,1]

xtset,clear

subsample_test res_social_exp_avg_share tiebout_75th_sample
bootstrap tiebout_75_difference=r(subsample_difference), nodots cluster(mun_code) seed(123456) reps(500): subsample_test res_social_exp_avg_share tiebout_75th_sample

local t75_share_b  : di %9.2f e(b)[1,1]
local t75_share_se : di %9.2f e(se)[1,1]

xtset,clear

subsample_test res_social_exp_avg_share coal_dist_median_sample
bootstrap ideology_median_difference=r(subsample_difference), nodots cluster(mun_code) seed(123456) reps(500): subsample_test res_social_exp_avg_share coal_dist_median_sample

local ideomed_share_b  : di %9.2f e(b)[1,1]
local ideomed_share_se : di %9.2f e(se)[1,1]

xtset,clear

subsample_test res_social_exp_avg_share coal_dist_75th_sample
bootstrap ideology_75_difference=r(subsample_difference), nodots cluster(mun_code) seed(123456) reps(500): subsample_test res_social_exp_avg_share coal_dist_75th_sample

local ideo75_share_b  : di %9.2f e(b)[1,1]
local ideo75_share_se : di %9.2f e(se)[1,1]

**********************************************************************
** BOOTSTRAP S.E.s FOR DIFFERENTIAL EFFECTS ON SOC. EXP. PER CAPITA **
**********************************************************************
xtset,clear

subsample_test res_social_exp_avg_pc oil_sample
bootstrap oil_difference=r(subsample_difference), nodots cluster(mun_code) seed(123456) reps(500): subsample_test res_social_exp_avg_pc oil_sample

local oil_pc_b  : di %9.2f e(b)[1,1]
local oil_pc_se : di %9.2f e(se)[1,1]

xtset,clear

subsample_test res_social_exp_avg_pc lame_duck
bootstrap lame_duck_difference=r(subsample_difference), nodots cluster(mun_code) seed(123456) reps(500): subsample_test res_social_exp_avg_pc lame_duck

local lameduck_pc_b  : di %9.2f e(b)[1,1]
local lameduck_pc_se : di %9.2f e(se)[1,1]

xtset,clear
subsample_test res_social_exp_avg_pc tiebout_median_sample
bootstrap tiebout_median_difference=r(subsample_difference), nodots cluster(mun_code) seed(123456) reps(500): subsample_test res_social_exp_avg_pc tiebout_median_sample

local tmed_pc_b  : di %9.2f e(b)[1,1]
local tmed_pc_se : di %9.2f e(se)[1,1]

xtset,clear
subsample_test res_social_exp_avg_pc tiebout_75th_sample
bootstrap tiebout_75_difference=r(subsample_difference), nodots cluster(mun_code) seed(123456) reps(500): subsample_test res_social_exp_avg_pc tiebout_75th_sample

local t75_pc_b  : di %9.2f e(b)[1,1]
local t75_pc_se : di %9.2f e(se)[1,1]

xtset,clear
subsample_test res_social_exp_avg_pc coal_dist_median_sample
bootstrap ideology_median_difference=r(subsample_difference), nodots cluster(mun_code) seed(123456) reps(500): subsample_test res_social_exp_avg_pc coal_dist_median_sample

local ideomed_pc_b  : di %9.2f e(b)[1,1]
local ideomed_pc_se : di %9.2f e(se)[1,1]

xtset,clear
subsample_test res_social_exp_avg_pc coal_dist_75th_sample
bootstrap ideology_75_difference=r(subsample_difference), nodots cluster(mun_code) seed(123456) reps(500): subsample_test res_social_exp_avg_pc coal_dist_75th_sample

local ideo75_pc_b  : di %9.2f e(b)[1,1]
local ideo75_pc_se : di %9.2f e(se)[1,1]

macro list


* write table
texdoc init "${root}/results/tables/table_bootstrap.tex", replace force

tex \begin{tabular*}{\textwidth}{l @{\extracolsep{\fill}} cccccc}
tex \toprule

tex \multirow{2}{*}{Outcome}				& \multicolumn{6}{c}{Subsample} 	   																													\\
tex \cmidrule(lr){2-7}
tex 										& Lame duck 					& Oil Windfall  			& \multicolumn{2}{c}{Tiebout competition}  	& \multicolumn{2}{c}{Ideology distance}   		\\
tex 										&            					& 				  			&  $<$ median	 &  $<$ 25th pct           & $>$ median	 		&  $> $ 75th pct		 \\
tex \midrule

tex Social expenditures    					& `lameduck_share_b'			&	`oil_share_b'			&	`tmed_share_b'		& `t75_share_b'		& `ideomed_share_b'		& `ideo75_share_b'		\\
tex share						    		& (`lameduck_share_se')			&		(`oil_share_se')	& (`tmed_share_se')		& (`t75_share_se')	& (`ideomed_share_se')	& (`ideo75_share_se')	\\

tex \midrule

tex Social expenditures    					& `lameduck_pc_b'				& `oil_pc_b'				& `tmed_pc_b'	 		& `t75_pc_b'		& `ideomed_pc_b'		& `ideo75_pc_b'			\\
tex per capita						    	& (`lameduck_pc_se')			& (`oil_pc_se')				& (`tmed_pc_se') 		& (`t75_pc_se')		& (`ideomed_pc_se')		& (`ideo75_pc_se')		\\

tex \bottomrule

tex \end{tabular*}

texdoc close
